<!DOCTYPE HTML>
<html lang="zh-CN">


<head>
    <meta charset="utf-8">
    <meta name="keywords" content="ES集群搭建与Kibana+head+IK配置, Java,Linux,Mysql,Redis,HTTP,操作系统,计算机网络,计算机组成原理,数据结构与算法,工具使用,性能优化">
    <meta name="description" content="本网站是个人兴趣爱好，总结分享经验，记录生活点滴的平台，希望在以后的学习旅途中，走出自己的风景。">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="renderer" content="webkit|ie-stand|ie-comp">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
    <!-- Global site tag (gtag.js) - Google Analytics -->


    <title>ES集群搭建与Kibana+head+IK配置 | 八戒取经路</title>
    <link rel="icon" type="image/png" href="/favicon.png">

    <link rel="stylesheet" type="text/css" href="/libs/awesome/css/all.css">
    <link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
    <link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
    <link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
    <link rel="stylesheet" type="text/css" href="/css/matery.css">
    <link rel="stylesheet" type="text/css" href="/css/my.css">

    <script src="/libs/jquery/jquery.min.js"></script>

<meta name="generator" content="Hexo 5.4.0">
<style>.github-emoji { position: relative; display: inline-block; width: 1.2em; min-height: 1.2em; overflow: hidden; vertical-align: top; color: transparent; }  .github-emoji > span { position: relative; z-index: 10; }  .github-emoji img, .github-emoji .fancybox { margin: 0 !important; padding: 0 !important; border: none !important; outline: none !important; text-decoration: none !important; user-select: none !important; cursor: auto !important; }  .github-emoji img { height: 1.2em !important; width: 1.2em !important; position: absolute !important; left: 50% !important; top: 50% !important; transform: translate(-50%, -50%) !important; user-select: none !important; cursor: auto !important; } .github-emoji-fallback { color: inherit; } .github-emoji-fallback img { opacity: 0 !important; }</style>
<link rel="alternate" href="/atom.xml" title="八戒取经路" type="application/atom+xml">
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>




<body>
    <header class="navbar-fixed">
    <nav id="headNav" class="bg-color nav-transparent">
        <div id="navContainer" class="nav-wrapper container">
            <div class="brand-logo">
                <a href="/" class="waves-effect waves-light">
                    
                    <img src="/medias/logo.png" class="logo-img" alt="LOGO">
                    
                    <span class="logo-span">八戒取经路</span>
                </a>
            </div>
            

<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fas fa-bars"></i></a>
<ul class="right nav-menu">
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">
      
      <i class="fas fa-home" style="zoom: 0.6;"></i>
      
      <span>首页</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/tags" class="waves-effect waves-light">
      
      <i class="fas fa-tags" style="zoom: 0.6;"></i>
      
      <span>标签</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/categories" class="waves-effect waves-light">
      
      <i class="fas fa-bookmark" style="zoom: 0.6;"></i>
      
      <span>分类</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/navigate" class="waves-effect waves-light">
      
      <i class="fas fa-location-arrow" style="zoom: 0.6;"></i>
      
      <span>导航</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/archives" class="waves-effect waves-light">
      
      <i class="fas fa-archive" style="zoom: 0.6;"></i>
      
      <span>归档</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/" class="waves-effect waves-light">

      
      <i class="fas fa-address-card" style="zoom: 0.6;"></i>
      
      <span>关于</span>
      <i class="fas fa-chevron-down" aria-hidden="true" style="zoom: 0.6;"></i>
    </a>
    <ul class="sub-nav menus_item_child ">
      
      <li>
        <a href="/about">
          
          <i class="fas fa-user-circle" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>关于我</span>
        </a>
      </li>
      
      <li>
        <a href="/aboutme">
          
          <i class="fa fa-user-secret" style="margin-top: -20px; zoom: 0.6;"></i>
          
          <span>Another</span>
        </a>
      </li>
      
    </ul>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/contact" class="waves-effect waves-light">
      
      <i class="fas fa-comments" style="zoom: 0.6;"></i>
      
      <span>留言板</span>
    </a>
    
  </li>
  
  <li class="hide-on-med-and-down nav-item">
    
    <a href="/friends" class="waves-effect waves-light">
      
      <i class="fas fa-address-book" style="zoom: 0.6;"></i>
      
      <span>友情链接</span>
    </a>
    
  </li>
  
  <li>
    <a href="#searchModal" class="modal-trigger waves-effect waves-light">
      <i id="searchIcon" class="fas fa-search" title="搜索" style="zoom: 0.85;"></i>
    </a>
  </li>
</ul>


<div id="mobile-nav" class="side-nav sidenav">

    <div class="mobile-head bg-color">
        
        <img src="/medias/logo.png" class="logo-img circle responsive-img">
        
        <div class="logo-name">八戒取经路</div>
        <div class="logo-desc">
            
            本网站是个人兴趣爱好，总结分享经验，记录生活点滴的平台，希望在以后的学习旅途中，走出自己的风景。
            
        </div>
    </div>

    

    <ul class="menu-list mobile-menu-list">
        
        <li class="m-nav-item">
	  
		<a href="/" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-home"></i>
			
			首页
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/tags" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-tags"></i>
			
			标签
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/categories" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-bookmark"></i>
			
			分类
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/navigate" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-location-arrow"></i>
			
			导航
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/archives" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-archive"></i>
			
			归档
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="javascript:;">
			
				<i class="fa-fw fas fa-address-card"></i>
			
			关于
			<span class="m-icon"><i class="fas fa-chevron-right"></i></span>
		</a>
            <ul  style="background:  ;" >
              
                <li>

                  <a href="/about " style="margin-left:75px">
				  
				   <i class="fa fas fa-user-circle" style="position: absolute;left:50px" ></i>
			      
		          <span>关于我</span>
                  </a>
                </li>
              
                <li>

                  <a href="/aboutme " style="margin-left:75px">
				  
				   <i class="fa fa fa-user-secret" style="position: absolute;left:50px" ></i>
			      
		          <span>Another</span>
                  </a>
                </li>
              
            </ul>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/contact" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-comments"></i>
			
			留言板
		</a>
          
        </li>
        
        <li class="m-nav-item">
	  
		<a href="/friends" class="waves-effect waves-light">
			
			    <i class="fa-fw fas fa-address-book"></i>
			
			友情链接
		</a>
          
        </li>
        
        
        <li><div class="divider"></div></li>
        <li>
            <a href="https://github.com/" class="waves-effect waves-light" target="_blank">
                <i class="fab fa-github-square fa-fw"></i>Fork Me
            </a>
        </li>
        
    </ul>
</div>


        </div>

        
            <style>
    .nav-transparent .github-corner {
        display: none !important;
    }

    .github-corner {
        position: absolute;
        z-index: 10;
        top: 0;
        right: 0;
        border: 0;
        transform: scale(1.1);
    }

    .github-corner svg {
        color: #0f9d58;
        fill: #fff;
        height: 64px;
        width: 64px;
    }

    .github-corner:hover .octo-arm {
        animation: a 0.56s ease-in-out;
    }

    .github-corner .octo-arm {
        animation: none;
    }

    @keyframes a {
        0%,
        to {
            transform: rotate(0);
        }
        20%,
        60% {
            transform: rotate(-25deg);
        }
        40%,
        80% {
            transform: rotate(10deg);
        }
    }
</style>

<a href="https://github.com/" class="github-corner tooltipped hide-on-med-and-down" target="_blank"
   data-tooltip="Fork Me" data-position="left" data-delay="50">
    <svg viewBox="0 0 250 250" aria-hidden="true">
        <path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path>
        <path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2"
              fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path>
        <path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z"
              fill="currentColor" class="octo-body"></path>
    </svg>
</a>
        
    </nav>

</header>

    



<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/0.jpg')">
    <div class="container" style="right: 0px;left: 0px;">
        <div class="row">
            <div class="col s12 m12 l12">
                <div class="brand">
                    <h1 class="description center-align post-title">ES集群搭建与Kibana+head+IK配置</h1>
                </div>
            </div>
        </div>
    </div>
</div>




<main class="post-container content">

    
    <link rel="stylesheet" href="/libs/tocbot/tocbot.css">
<style>
    #articleContent h1::before,
    #articleContent h2::before,
    #articleContent h3::before,
    #articleContent h4::before,
    #articleContent h5::before,
    #articleContent h6::before {
        display: block;
        content: " ";
        height: 100px;
        margin-top: -100px;
        visibility: hidden;
    }

    #articleContent :focus {
        outline: none;
    }

    .toc-fixed {
        position: fixed;
        top: 64px;
    }

    .toc-widget {
        width: 345px;
        padding-left: 20px;
    }

    .toc-widget .toc-title {
        padding: 35px 0 15px 17px;
        font-size: 1.5rem;
        font-weight: bold;
        line-height: 1.5rem;
    }

    .toc-widget ol {
        padding: 0;
        list-style: none;
    }

    #toc-content {
        padding-bottom: 30px;
        overflow: auto;
    }

    #toc-content ol {
        padding-left: 10px;
    }

    #toc-content ol li {
        padding-left: 10px;
    }

    #toc-content .toc-link:hover {
        color: #42b983;
        font-weight: 700;
        text-decoration: underline;
    }

    #toc-content .toc-link::before {
        background-color: transparent;
        max-height: 25px;

        position: absolute;
        right: 23.5vw;
        display: block;
    }

    #toc-content .is-active-link {
        color: #42b983;
    }

    #floating-toc-btn {
        position: fixed;
        right: 15px;
        bottom: 76px;
        padding-top: 15px;
        margin-bottom: 0;
        z-index: 998;
    }

    #floating-toc-btn .btn-floating {
        width: 48px;
        height: 48px;
    }

    #floating-toc-btn .btn-floating i {
        line-height: 48px;
        font-size: 1.4rem;
    }
</style>
<div class="row">
    <div id="main-content" class="col s12 m12 l9">
        <!-- 文章内容详情 -->
<div id="artDetail">
    <div class="card">
        <div class="card-content article-info">
            <div class="row tag-cate">
                <div class="col s7">
                    
                    <div class="article-tag">
                        
                            <a href="/tags/Elasticsearch%E9%9B%86%E7%BE%A4/">
                                <span class="chip bg-color">Elasticsearch集群</span>
                            </a>
                        
                            <a href="/tags/IK/">
                                <span class="chip bg-color">IK</span>
                            </a>
                        
                            <a href="/tags/Kibana/">
                                <span class="chip bg-color">Kibana</span>
                            </a>
                        
                            <a href="/tags/head%E6%8F%92%E4%BB%B6/">
                                <span class="chip bg-color">head插件</span>
                            </a>
                        
                    </div>
                    
                </div>
                <div class="col s5 right-align">
                    
                </div>
            </div>

            <div class="post-info">
                
                <div class="post-date info-break-policy">
                    <i class="far fa-calendar-minus fa-fw"></i>发布日期:&nbsp;&nbsp;
                    2021-04-11
                </div>
                

                

                
                <div class="info-break-policy">
                    <i class="far fa-file-word fa-fw"></i>文章字数:&nbsp;&nbsp;
                    5.1k
                </div>
                

                

                
            </div>
        </div>
        <hr class="clearfix">

        

        

        <div class="card-content article-card-content">
            <div id="articleContent">
                <h4 id="一、概述"><a href="#一、概述" class="headerlink" title="一、概述"></a><code>一、概述</code></h4><p>我们为什么要安装 <code>ES</code> 集群？因为生产没人用单机版本，单机版本那都是用来玩的“玩具”。本篇文章基于 <code>Elasticsearch 7.X +CentOS 7.6</code> 版本进行安装（这里劝诫大家不要再去学习 <code>7.X</code> 之前的版本了，这个版本对之前的版本进行了大改），通过本篇学习你能学到如何在 <code>Linux</code> 下安装 <code>ES</code> 集群，如何整合 <code>IK</code> 分词器，如何整合 <code>head</code> 插件，如何整合 <code>Kibana</code> 客户端等。<code>ES</code> 是 <code>java</code> 开发的，在安装确保 <code>JDK</code> 环境已经配置好了。今天的集群网络拓扑图如下：</p>
<table>
<thead>
<tr>
<th>IP</th>
<th>PORT</th>
</tr>
</thead>
<tbody><tr>
<td>192.168.56.143</td>
<td>9200</td>
</tr>
<tr>
<td>192.168.56.144</td>
<td>9200</td>
</tr>
<tr>
<td>192.168.56.145</td>
<td>9200</td>
</tr>
</tbody></table>
<h4 id="二、集群安装"><a href="#二、集群安装" class="headerlink" title="二、集群安装"></a><code>二、集群安装</code></h4><blockquote>
<p>说明：这里就以 192.168.56.143 安装为例，其它两个节点，只要将 143 上的配置文件修改后，通过 scp 传过去进行简单修改即可。</p>
</blockquote>
<ul>
<li><h5 id="Linux-参数配置"><a href="#Linux-参数配置" class="headerlink" title="Linux 参数配置"></a><code>Linux 参数配置</code></h5><blockquote>
<p>注意：Linux 内核参数的调整并不仅仅在 ES 的安装过程中需要注意，其它中间件产品的安装也同样需要注意调整，例如：MySQL、Oracle、MQ 等</p>
</blockquote>
<p><strong>修改每个进程最大同时打开文件数、最大线程数：</strong></p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># vim /etc/security/limits.conf</span>
在最后添加如下内容<span class="token punctuation">(</span>注意 es 表示你的用户名，给哪一个用户设置的意思<span class="token punctuation">)</span>：
es soft nofile 65536  <span class="token comment" spellcheck="true"># es 用户最大同时打开soft类型文件数</span>
es hard nofile 65536 <span class="token comment" spellcheck="true"># es 用户最大同时打开hard类型文件数</span>
es soft nproc 4096  <span class="token comment" spellcheck="true"># es 用户最大同时打开soft类型线程数</span>
es hard nproc 4096 <span class="token comment" spellcheck="true"># es 用户最大同时打开hard类型线程数</span>
</code></pre>
<p><strong>修改最大虚拟内存大小：</strong></p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># vim /etc/sysctl.conf</span>
<span class="token comment" spellcheck="true"># 增加如下：</span>
vm.max_map_count<span class="token operator">=</span>262144
<span class="token comment" spellcheck="true"># 修改完之后，执行如下命令生效</span>
<span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># sysctl -p</span>
</code></pre>
</li>
<li><h5 id="创建-es-用户并授权"><a href="#创建-es-用户并授权" class="headerlink" title="创建 es 用户并授权"></a><code>创建 es 用户并授权</code></h5><p>在 <code>7.X</code> 版本之后不允许使用 <code>root</code> 用户启动 <code>ES</code> 进程，因此需要创建专门用户启动 <code>ES</code> 进程的的用户</p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># groupadd es ## 创建 es 用户组</span>
<span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true">#  useradd -m -g es es ## 创建用户名为</span>
<span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true">#  passwd es  ## 设置 es 用户的密码</span>
<span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true">#   visudo  ## 配置 es 用户的sudo 权限在打开的编辑配置中，添加 es    ALL=(ALL)    NOPASSWD:ALL 这行内容 (表示通过es 用户启动的进程时候，授予root的权限，注意：在安装其他中间件时也要习惯用非root用户作为管理用户)</span>
</code></pre>
</li>
<li><h5 id="下载安装包并解压"><a href="#下载安装包并解压" class="headerlink" title="下载安装包并解压"></a><code>下载安装包并解压</code></h5><p>下载安装包我通过<a target="_blank" rel="noopener" href="https://mirrors.huaweicloud.com/">华为镜像</a>下载对应的安装包（官网实在太慢~~），在链接地址搜索 <code>Elasticsearch</code> 然后点击进去找到我们本次安装的版本，复制链接地址，通过 <code>wget</code> 命令下载：</p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># wget https://repo.huaweicloud.com/elasticsearch/7.8.0/elasticsearch-7.8.0-linux-x86_64.tar.gz</span>
<span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># mkdir /usr/local/elasticsearch -pv ## 创建目录</span>
<span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># tar -zxvf elasticsearch-7.8.0-linux-x86_64.tar.gz -c /usr/local/elasticsearch/  ## 解压</span>
</code></pre>
</li>
<li><h5 id="修改-ES-配置文件与JVM配置"><a href="#修改-ES-配置文件与JVM配置" class="headerlink" title="修改 ES 配置文件与JVM配置"></a><code>修改 ES 配置文件与JVM配置</code></h5><pre class=" language-yaml"><code class="language-yaml"><span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># cd /usr/local/elasticsearch/elasticsearch-7.8.0/config/</span>
<span class="token punctuation">[</span>root@centos7 config<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># vim elasticsearch.yml ## 编辑并修改为如下内容</span>
<span class="token comment" spellcheck="true"># 增加以下内容</span>
<span class="token comment" spellcheck="true"># 集群名称必须相同</span>
<span class="token key atrule">cluster.name</span><span class="token punctuation">:</span> es<span class="token punctuation">-</span>app
<span class="token key atrule">node.name</span><span class="token punctuation">:</span> node<span class="token punctuation">-</span><span class="token number">1  </span><span class="token comment" spellcheck="true">## 另外两个节点分别为 node-2  node-3</span>
<span class="token comment" spellcheck="true"># 当前节点是否可以被选举为master节点，是：true、否：false</span>
<span class="token key atrule">node.master</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment" spellcheck="true"># 当前节点是否用于存储数据，是：true、否：false</span>
<span class="token key atrule">node.data</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment" spellcheck="true"># 数据和日志存储的地方，建议与es的安装目录区分，方式es删除后数据的丢失,这两个目录后面需要创建并设置好权限</span>
<span class="token key atrule">path.data</span><span class="token punctuation">:</span> /es/data
<span class="token key atrule">path.logs</span><span class="token punctuation">:</span> /es/logs
<span class="token comment" spellcheck="true"># 需求锁住物理内存，是：true、否：false</span>
<span class="token key atrule">bootstrap.memory_lock</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
<span class="token comment" spellcheck="true"># SecComp检测，是：true、否：false</span>
<span class="token key atrule">bootstrap.system_call_filter</span><span class="token punctuation">:</span> <span class="token boolean important">false</span>
<span class="token key atrule">network.host</span><span class="token punctuation">:</span> 0.0.0.0
<span class="token comment" spellcheck="true"># 集群必须要配置此项，yourIp修改为自己的本机服务器的外网ip，否则集群失败</span>
<span class="token key atrule">network.publish_host</span><span class="token punctuation">:</span> 192.168.56.143
<span class="token comment" spellcheck="true"># 主机访问的端口号</span>
<span class="token key atrule">http.port</span><span class="token punctuation">:</span> <span class="token number">9200</span>
<span class="token comment" spellcheck="true"># es7.x 之后新增的配置，写入候选主节点的设备地址，在开启服务后可以被选为主节点</span>
<span class="token comment" spellcheck="true"># es7之后，不需要discover.zen.ping.unicast.hosts这个参数，用discovery.seed_hosts替换，脑列控制由集群自主控制</span>
<span class="token key atrule">discovery.seed_hosts</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"192.168.56.143"</span><span class="token punctuation">,</span><span class="token string">"192.168.56.144"</span><span class="token punctuation">,</span><span class="token string">"192.168.56.145"</span><span class="token punctuation">]</span>
<span class="token comment" spellcheck="true"># es7.x 之后新增的配置，初始化一个新的集群时需要此配置来选举master</span>
<span class="token key atrule">cluster.initial_master_nodes</span><span class="token punctuation">:</span> <span class="token punctuation">[</span><span class="token string">"192.168.56.143"</span><span class="token punctuation">,</span><span class="token string">"192.168.56.144"</span><span class="token punctuation">,</span><span class="token string">"192.168.56.145"</span><span class="token punctuation">]</span>
<span class="token comment" spellcheck="true"># 是否支持跨域，是：true，在使用head插件时需要此配置</span>
<span class="token key atrule">http.cors.enabled</span><span class="token punctuation">:</span> <span class="token boolean important">true</span>
<span class="token comment" spellcheck="true"># "*" 表示支持所有域名</span>
<span class="token key atrule">http.cors.allow-origin</span><span class="token punctuation">:</span> <span class="token string">"*"</span>
</code></pre>
<p>修改与 <code>ES</code> 配置文件相同目录下的 <code>jvm.options</code> 配置文件，主要用于控制 <code>JVM</code> 的参数配置</p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 config<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># vim config/jvm.options</span>
<span class="token comment" spellcheck="true"># 按需修改如下内存大小即可</span>
-Xms1g
-Xmx1g
<span class="token punctuation">..</span><span class="token punctuation">..</span>.
<span class="token comment" spellcheck="true"># 其它配置项都可以进行调整，因为是 java 开发的，你就当做 java 工程去优化 JVM 参数即可，这又涉及到 JVM 的优化内容了，后面我会出相关文章进行介绍</span>
</code></pre>
</li>
<li><h5 id="创建必要的目录并授权"><a href="#创建必要的目录并授权" class="headerlink" title="创建必要的目录并授权"></a><code>创建必要的目录并授权</code></h5><pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># mkdir /es/{data,logs} -pv  ## 创建数据目录和日志目录</span>
<span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># chown -R es:es /es  ## 授权</span>
<span class="token punctuation">[</span>root@centos7 es<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># cd /usr/local/</span>
<span class="token punctuation">[</span>root@centos7 local<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># chown -R es:es /es ./elasticsearch  ## 授权</span>
注意，权限一定要设置成 es 否则启动会报错
</code></pre>
</li>
<li><h5 id="集群启动"><a href="#集群启动" class="headerlink" title="集群启动"></a><code>集群启动</code></h5><blockquote>
<p>注意：到这里我们已经配置好了 192.168.56.143 节点的配置，另外两个节点配置步骤类似，唯一不同的是，你需要将 es 的配置文件通过 scp 传到另外两个节点上，修改 node.name 、network.publish_host 配置项内容为指定节点配置即可，这里就不重复了。</p>
</blockquote>
<p>三台节点分别执行如下脚本进行启动，启动没有先后之分，<code>7.X</code> 版本在节点全部启动后会自动选取主节点</p>
<pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">## 注意，到这里前面的所有操作都在 root 用户下进行，从这一步开始切到 es 用户下启动进程</span>
<span class="token punctuation">[</span>es@centos7 /<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ./usr/local/elasticsearch/elasticsearch-7.8.0/bin/elasticsearch  ## 前台启动方式，如果测试时想在控制台看日志启动情况，可以使用这种方式，但是生产环境肯定不能用这种方式启动</span>
<span class="token punctuation">[</span>es@centos7 /<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># ./usr/local/elasticsearch/elasticsearch-7.8.0/bin/elasticsearch  ## 后台启动方式，生产推荐启动方式</span>
</code></pre>
</li>
<li><h5 id="集群测试"><a href="#集群测试" class="headerlink" title="集群测试"></a><code>集群测试</code></h5><pre class=" language-bash"><code class="language-bash"><span class="token comment" spellcheck="true">## 通过浏览器访问如下地址查看集群启动状态</span>
http://192.168.56.145:9200/_cat/health?v
<span class="token comment" spellcheck="true">## 可以看到如下内容</span>
epoch      timestamp cluster status node.total node.data shards pri relo init unassign pending_tasks max_task_wait_time active_shards_percent
1618143879 12:24:39  es-app  green           3         3      0   0    0    0        0             0                  -                100.0%
<span class="token comment" spellcheck="true">## 查看集群信息</span>
<span class="token punctuation">[</span>es@centos7 bin<span class="token punctuation">]</span>$ curl 192.168.56.143:9200/_cat/nodes
192.168.56.144 44 96 0 0.03 0.04 0.05 dilmrt - node-2
192.168.56.145 51 96 0 0.00 0.01 0.05 dilmrt * node-3 <span class="token comment" spellcheck="true">## 带 * 号的表示主节点</span>
192.168.56.143 59 96 0 0.01 0.02 0.10 dilmrt - node-1

<span class="token comment" spellcheck="true">##检查分片是否都正常</span>
<span class="token punctuation">[</span>es@centos7 bin<span class="token punctuation">]</span>$ curl 192.168.56.143:9200/_cat/shards  <span class="token comment" spellcheck="true">## 如果出现分片的状态不是 STARTED 而是UNASSIGNED说明分片不正常，我就遇到过如果磁盘空间使用量超过 85% 集群的状态不是 green 而是 yellow ，此时分片都是 UNASSIGNED 状态，最终将磁盘空间降下来后分片正常了</span>
.apm-agent-configuration       0 r STARTED  0    208b 192.168.56.143 node-1
.apm-agent-configuration       0 p STARTED  0    208b 192.168.56.144 node-2
ilm-history-2-000001           0 p STARTED            192.168.56.145 node-3
ilm-history-2-000001           0 r STARTED            192.168.56.143 node-1
.kibana_1                      0 r STARTED 64 120.4kb 192.168.56.145 node-3
.kibana_1                      0 p STARTED 64 120.4kb 192.168.56.144 node-2
.apm-custom-link               0 r STARTED  0    208b 192.168.56.143 node-1
.apm-custom-link               0 p STARTED  0    208b 192.168.56.144 node-2
.kibana_task_manager_1         0 p STARTED  5  11.1kb 192.168.56.145 node-3
.kibana_task_manager_1         0 r STARTED  5  11.1kb 192.168.56.143 node-1
customer                       0 r STARTED  1   3.5kb 192.168.56.145 node-3
customer                       0 p STARTED  1   3.5kb 192.168.56.144 node-2
user                           2 p STARTED  1   3.5kb 192.168.56.145 node-3  <span class="token comment" spellcheck="true">## p 表示 primary shard 主分片，前面的数字表示分片的数量</span>
user                           2 r STARTED  1   3.5kb 192.168.56.143 node-1   <span class="token comment" spellcheck="true">## r 表示 replica shard 副本分片</span>
user                           1 r STARTED  0    208b 192.168.56.145 node-3
user                           1 p STARTED  0    208b 192.168.56.144 node-2
user                           0 r STARTED  0    208b 192.168.56.143 node-1
user                           0 p STARTED  0    208b 192.168.56.144 node-2
.kibana-event-log-7.8.0-000001 0 r STARTED  3  15.5kb 192.168.56.143 node-1
.kibana-event-log-7.8.0-000001 0 p STARTED  3  15.5kb 192.168.56.144 node-2
</code></pre>
</li>
<li><h5 id="问题总结"><a href="#问题总结" class="headerlink" title="问题总结"></a><code>问题总结</code></h5><p><strong><code>问题1：配置文件的权限问题在调整过程中忘记改成 es 用户权限了</code></strong></p>
<pre class=" language-java"><code class="language-java"><span class="token punctuation">[</span>es@<span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span><span class="token operator">*</span> bin<span class="token punctuation">]</span>$ <span class="token punctuation">.</span>/elasticsearch
Exception in thread <span class="token string">"main"</span> <span class="token number">2021</span><span class="token operator">-</span><span class="token number">04</span><span class="token operator">-</span><span class="token number">03</span> <span class="token number">17</span><span class="token operator">:</span><span class="token number">36</span><span class="token operator">:</span><span class="token number">23</span><span class="token punctuation">,</span><span class="token number">881</span> main ERROR No log4j2 configuration file found<span class="token punctuation">.</span> Using <span class="token keyword">default</span> configuration<span class="token operator">:</span> logging only errors to the console<span class="token punctuation">.</span> Set system property <span class="token string">'log4j2.debug'</span> to show Log4j2 internal initialization logging<span class="token punctuation">.</span>
<span class="token number">2021</span><span class="token operator">-</span><span class="token number">04</span><span class="token operator">-</span><span class="token number">03</span> <span class="token number">17</span><span class="token operator">:</span><span class="token number">36</span><span class="token operator">:</span><span class="token number">24</span><span class="token punctuation">,</span><span class="token number">113</span> main ERROR Could not register mbeans java<span class="token punctuation">.</span>security<span class="token punctuation">.</span>AccessControlException<span class="token operator">:</span> access <span class="token function">denied</span> <span class="token punctuation">(</span><span class="token string">"javax.management.MBeanTrustPermission"</span> <span class="token string">"register"</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>security<span class="token punctuation">.</span>AccessControlContext<span class="token punctuation">.</span><span class="token function">checkPermission</span><span class="token punctuation">(</span>AccessControlContext<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">472</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>SecurityManager<span class="token punctuation">.</span><span class="token function">checkPermission</span><span class="token punctuation">(</span>SecurityManager<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">585</span><span class="token punctuation">)</span>
        at com<span class="token punctuation">.</span>sun<span class="token punctuation">.</span>jmx<span class="token punctuation">.</span>interceptor<span class="token punctuation">.</span>DefaultMBeanServerInterceptor<span class="token punctuation">.</span><span class="token function">checkMBeanTrustPermission</span><span class="token punctuation">(</span>DefaultMBeanServerInterceptor<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">1848</span><span class="token punctuation">)</span>
        at com<span class="token punctuation">.</span>sun<span class="token punctuation">.</span>jmx<span class="token punctuation">.</span>interceptor<span class="token punctuation">.</span>DefaultMBeanServerInterceptor<span class="token punctuation">.</span><span class="token function">registerMBean</span><span class="token punctuation">(</span>DefaultMBeanServerInterceptor<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">322</span><span class="token punctuation">)</span>
        at com<span class="token punctuation">.</span>sun<span class="token punctuation">.</span>jmx<span class="token punctuation">.</span>mbeanserver<span class="token punctuation">.</span>JmxMBeanServer<span class="token punctuation">.</span><span class="token function">registerMBean</span><span class="token punctuation">(</span>JmxMBeanServer<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">522</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>jmx<span class="token punctuation">.</span>Server<span class="token punctuation">.</span><span class="token function">register</span><span class="token punctuation">(</span>Server<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">389</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>jmx<span class="token punctuation">.</span>Server<span class="token punctuation">.</span><span class="token function">reregisterMBeansAfterReconfigure</span><span class="token punctuation">(</span>Server<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">167</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>jmx<span class="token punctuation">.</span>Server<span class="token punctuation">.</span><span class="token function">reregisterMBeansAfterReconfigure</span><span class="token punctuation">(</span>Server<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">140</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>LoggerContext<span class="token punctuation">.</span><span class="token function">setConfiguration</span><span class="token punctuation">(</span>LoggerContext<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">556</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>LoggerContext<span class="token punctuation">.</span><span class="token function">reconfigure</span><span class="token punctuation">(</span>LoggerContext<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">617</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>LoggerContext<span class="token punctuation">.</span><span class="token function">reconfigure</span><span class="token punctuation">(</span>LoggerContext<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">634</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>LoggerContext<span class="token punctuation">.</span><span class="token function">start</span><span class="token punctuation">(</span>LoggerContext<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">229</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>impl<span class="token punctuation">.</span>Log4jContextFactory<span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span>Log4jContextFactory<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">242</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>core<span class="token punctuation">.</span>impl<span class="token punctuation">.</span>Log4jContextFactory<span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span>Log4jContextFactory<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">45</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>LogManager<span class="token punctuation">.</span><span class="token function">getContext</span><span class="token punctuation">(</span>LogManager<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">174</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>apache<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>log4j<span class="token punctuation">.</span>LogManager<span class="token punctuation">.</span><span class="token function">getLogger</span><span class="token punctuation">(</span>LogManager<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">618</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>common<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>ESLoggerFactory<span class="token punctuation">.</span><span class="token function">getLogger</span><span class="token punctuation">(</span>ESLoggerFactory<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">54</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>common<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>ESLoggerFactory<span class="token punctuation">.</span><span class="token function">getLogger</span><span class="token punctuation">(</span>ESLoggerFactory<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">62</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>common<span class="token punctuation">.</span>logging<span class="token punctuation">.</span>Loggers<span class="token punctuation">.</span><span class="token function">getLogger</span><span class="token punctuation">(</span>Loggers<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">101</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>ExceptionsHelper<span class="token punctuation">.</span>&lt;clinit<span class="token operator">></span><span class="token punctuation">(</span>ExceptionsHelper<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">42</span><span class="token punctuation">)</span>
        at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>ElasticsearchException<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span>ElasticsearchException<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">663</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>String<span class="token punctuation">.</span><span class="token function">valueOf</span><span class="token punctuation">(</span>String<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">2994</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>io<span class="token punctuation">.</span>PrintStream<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>PrintStream<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">821</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>Throwable$WrappedPrintStream<span class="token punctuation">.</span><span class="token function">println</span><span class="token punctuation">(</span>Throwable<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">748</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>Throwable<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span>Throwable<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">655</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>Throwable<span class="token punctuation">.</span><span class="token function">printStackTrace</span><span class="token punctuation">(</span>Throwable<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">643</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>ThreadGroup<span class="token punctuation">.</span><span class="token function">uncaughtException</span><span class="token punctuation">(</span>ThreadGroup<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">1061</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>ThreadGroup<span class="token punctuation">.</span><span class="token function">uncaughtException</span><span class="token punctuation">(</span>ThreadGroup<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">1052</span><span class="token punctuation">)</span>
        at java<span class="token punctuation">.</span>lang<span class="token punctuation">.</span>Thread<span class="token punctuation">.</span><span class="token function">dispatchUncaughtException</span><span class="token punctuation">(</span>Thread<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">1959</span><span class="token punctuation">)</span>
SettingsException<span class="token punctuation">[</span>Failed to load settings from <span class="token operator">/</span>usr<span class="token operator">/</span>local<span class="token operator">/</span>elasticsearch<span class="token operator">-</span><span class="token number">5.6</span><span class="token punctuation">.</span><span class="token number">0</span><span class="token operator">/</span>config<span class="token operator">/</span>elasticsearch<span class="token punctuation">.</span>yml<span class="token punctuation">]</span><span class="token punctuation">;</span> nested<span class="token operator">:</span> AccessDeniedException<span class="token punctuation">[</span><span class="token operator">/</span>usr<span class="token operator">/</span>local<span class="token operator">/</span>elasticsearch<span class="token operator">-</span><span class="token number">5.6</span><span class="token punctuation">.</span><span class="token number">0</span><span class="token operator">/</span>config<span class="token operator">/</span>elasticsearch<span class="token punctuation">.</span>yml<span class="token punctuation">]</span><span class="token punctuation">;</span>
at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>node<span class="token punctuation">.</span>InternalSettingsPreparer<span class="token punctuation">.</span><span class="token function">prepareEnvironment</span><span class="token punctuation">(</span>InternalSettingsPreparer<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">102</span><span class="token punctuation">)</span>
at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>cli<span class="token punctuation">.</span>EnvironmentAwareCommand<span class="token punctuation">.</span><span class="token function">createEnv</span><span class="token punctuation">(</span>EnvironmentAwareCommand<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">72</span><span class="token punctuation">)</span>
at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>cli<span class="token punctuation">.</span>EnvironmentAwareCommand<span class="token punctuation">.</span><span class="token function">execute</span><span class="token punctuation">(</span>EnvironmentAwareCommand<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">67</span><span class="token punctuation">)</span>
at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>cli<span class="token punctuation">.</span>Command<span class="token punctuation">.</span><span class="token function">mainWithoutErrorHandling</span><span class="token punctuation">(</span>Command<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">134</span><span class="token punctuation">)</span>
at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>cli<span class="token punctuation">.</span>Command<span class="token punctuation">.</span><span class="token function">main</span><span class="token punctuation">(</span>Command<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">90</span><span class="token punctuation">)</span>
at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>bootstrap<span class="token punctuation">.</span>Elasticsearch<span class="token punctuation">.</span><span class="token function">main</span><span class="token punctuation">(</span>Elasticsearch<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">91</span><span class="token punctuation">)</span>
at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>bootstrap<span class="token punctuation">.</span>Elasticsearch<span class="token punctuation">.</span><span class="token function">main</span><span class="token punctuation">(</span>Elasticsearch<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">84</span><span class="token punctuation">)</span>
Caused by<span class="token operator">:</span> java<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>file<span class="token punctuation">.</span>AccessDeniedException<span class="token operator">:</span> <span class="token operator">/</span>usr<span class="token operator">/</span>local<span class="token operator">/</span>elasticsearch<span class="token operator">-</span><span class="token number">5.6</span><span class="token punctuation">.</span><span class="token number">0</span><span class="token operator">/</span>config<span class="token operator">/</span>elasticsearch<span class="token punctuation">.</span>yml
at sun<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>fs<span class="token punctuation">.</span>UnixException<span class="token punctuation">.</span><span class="token function">translateToIOException</span><span class="token punctuation">(</span>UnixException<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">84</span><span class="token punctuation">)</span>
at sun<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>fs<span class="token punctuation">.</span>UnixException<span class="token punctuation">.</span><span class="token function">rethrowAsIOException</span><span class="token punctuation">(</span>UnixException<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">102</span><span class="token punctuation">)</span>
at sun<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>fs<span class="token punctuation">.</span>UnixException<span class="token punctuation">.</span><span class="token function">rethrowAsIOException</span><span class="token punctuation">(</span>UnixException<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">107</span><span class="token punctuation">)</span>
at sun<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>fs<span class="token punctuation">.</span>UnixFileSystemProvider<span class="token punctuation">.</span><span class="token function">newByteChannel</span><span class="token punctuation">(</span>UnixFileSystemProvider<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">214</span><span class="token punctuation">)</span>
at java<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>file<span class="token punctuation">.</span>Files<span class="token punctuation">.</span><span class="token function">newByteChannel</span><span class="token punctuation">(</span>Files<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">361</span><span class="token punctuation">)</span>
at java<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>file<span class="token punctuation">.</span>Files<span class="token punctuation">.</span><span class="token function">newByteChannel</span><span class="token punctuation">(</span>Files<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">407</span><span class="token punctuation">)</span>
at java<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>file<span class="token punctuation">.</span>spi<span class="token punctuation">.</span>FileSystemProvider<span class="token punctuation">.</span><span class="token function">newInputStream</span><span class="token punctuation">(</span>FileSystemProvider<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">384</span><span class="token punctuation">)</span>
at java<span class="token punctuation">.</span>nio<span class="token punctuation">.</span>file<span class="token punctuation">.</span>Files<span class="token punctuation">.</span><span class="token function">newInputStream</span><span class="token punctuation">(</span>Files<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">152</span><span class="token punctuation">)</span>
at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>common<span class="token punctuation">.</span>settings<span class="token punctuation">.</span>SettingsBuilder<span class="token punctuation">.</span><span class="token function">loadFromPath</span><span class="token punctuation">(</span>Settings<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">1032</span><span class="token punctuation">)</span>atorg<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>node<span class="token punctuation">.</span>InternalSettingsPreparer<span class="token punctuation">.</span><span class="token function">prepareEnvironment</span><span class="token punctuation">(</span>InternalSettingsPreparer<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>6more<span class="token punctuation">[</span>elk<span class="token annotation punctuation">@dockerbin</span><span class="token punctuation">]</span> Builder<span class="token punctuation">.</span><span class="token function">loadFromPath</span><span class="token punctuation">(</span>Settings<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">1032</span><span class="token punctuation">)</span>at org<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>node<span class="token punctuation">.</span>InternalSettingsPreparer<span class="token punctuation">.</span><span class="token function">prepareEnvironment</span><span class="token punctuation">(</span>InternalSettingsPreparer<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span> <span class="token number">6</span> more<span class="token punctuation">[</span>elk<span class="token annotation punctuation">@docker</span> bin<span class="token punctuation">]</span>Builder<span class="token punctuation">.</span><span class="token function">loadFromPath</span><span class="token punctuation">(</span>Settings<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">1032</span><span class="token punctuation">)</span>atorg<span class="token punctuation">.</span>elasticsearch<span class="token punctuation">.</span>node<span class="token punctuation">.</span>InternalSettingsPreparer<span class="token punctuation">.</span><span class="token function">prepareEnvironment</span><span class="token punctuation">(</span>InternalSettingsPreparer<span class="token punctuation">.</span>java<span class="token operator">:</span><span class="token number">100</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span>6more<span class="token punctuation">[</span>elk<span class="token annotation punctuation">@dockerbin</span><span class="token punctuation">]</span>
</code></pre>
<p><strong><code>解决办法：</code></strong></p>
<p>看到“<code>Caused by: java.nio.file.AccessDeniedException: /usr/local/elasticsearch-7.8.0/config/elasticsearch.yml</code>”的提示，就去检查目录的权限，果然是 <code>root:root</code> 权限，使用 <code>es</code> 用户去启动，就报错了。<br>将目录权限改成 <code>es:es</code> ，并且如果 <code>/es/data 、 /es/logs</code>中有内容要删掉，就好了(<code>chown -R es:es elasticsearch-7.8.0</code> 修改目录所有者为 <code>es</code> )</p>
<p><strong><code>问题2：elasticsearch7 出现master not discovered yet, this node has not previously joined a bootstrapped (v7+)</code></strong></p>
<pre class=" language-java"><code class="language-java"><span class="token punctuation">[</span><span class="token number">2021</span><span class="token operator">-</span><span class="token number">03</span><span class="token operator">-</span>21T15<span class="token operator">:</span><span class="token number">52</span><span class="token operator">:</span><span class="token number">32</span><span class="token punctuation">,</span><span class="token number">213</span><span class="token punctuation">]</span><span class="token punctuation">[</span>INFO <span class="token punctuation">]</span><span class="token punctuation">[</span>o<span class="token punctuation">.</span>e<span class="token punctuation">.</span>c<span class="token punctuation">.</span>c<span class="token punctuation">.</span>ClusterBootstrapService<span class="token punctuation">]</span> <span class="token punctuation">[</span>node<span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">]</span> skipping cluster bootstrapping as local node does not match bootstrap requirements<span class="token operator">:</span> <span class="token punctuation">[</span>node<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span>
<span class="token punctuation">[</span><span class="token number">2021</span><span class="token operator">-</span><span class="token number">03</span><span class="token operator">-</span><span class="token number">2</span><span class="token operator">-</span>21T15<span class="token operator">:</span><span class="token number">52</span><span class="token operator">:</span><span class="token number">42</span><span class="token punctuation">,</span><span class="token number">220</span><span class="token punctuation">]</span><span class="token punctuation">[</span>WARN <span class="token punctuation">]</span><span class="token punctuation">[</span>o<span class="token punctuation">.</span>e<span class="token punctuation">.</span>c<span class="token punctuation">.</span>c<span class="token punctuation">.</span>ClusterFormationFailureHelper<span class="token punctuation">]</span> <span class="token punctuation">[</span>node<span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">]</span> master not discovered yet<span class="token punctuation">,</span> <span class="token keyword">this</span> node has not previously joined a <span class="token function">bootstrapped</span> <span class="token punctuation">(</span>v7<span class="token operator">+</span><span class="token punctuation">)</span> cluster<span class="token punctuation">,</span> and <span class="token keyword">this</span> node must discover master<span class="token operator">-</span>eligible nodes <span class="token punctuation">[</span>node<span class="token operator">-</span><span class="token number">1</span><span class="token punctuation">]</span> to bootstrap a cluster<span class="token operator">:</span> have discovered <span class="token punctuation">[</span><span class="token punctuation">]</span><span class="token punctuation">;</span> discovery will <span class="token keyword">continue</span> using <span class="token punctuation">[</span><span class="token number">192.168</span><span class="token punctuation">.</span><span class="token number">56.143</span><span class="token operator">:</span><span class="token number">9300</span><span class="token punctuation">]</span> from hosts providers and <span class="token punctuation">[</span><span class="token punctuation">{</span>node<span class="token operator">-</span><span class="token number">2</span><span class="token punctuation">}</span><span class="token punctuation">{</span>nU2Duwl8Su<span class="token operator">-</span>qZ7N3rcfwWA<span class="token punctuation">}</span><span class="token punctuation">{</span>4OqPHF<span class="token operator">-</span>FRlyb_F7xhYoAow<span class="token punctuation">}</span><span class="token punctuation">{</span><span class="token number">192.168</span><span class="token punctuation">.</span><span class="token number">56.143</span><span class="token punctuation">}</span><span class="token punctuation">{</span><span class="token number">192.168</span><span class="token punctuation">.</span><span class="token number">56.143</span><span class="token operator">:</span><span class="token number">9300</span><span class="token punctuation">}</span><span class="token punctuation">{</span>ml<span class="token punctuation">.</span>machine_memory<span class="token operator">=</span><span class="token number">67267657728</span><span class="token punctuation">,</span> xpack<span class="token punctuation">.</span>installed<span class="token operator">=</span><span class="token boolean">true</span><span class="token punctuation">,</span> ml<span class="token punctuation">.</span>max_open_jobs<span class="token operator">=</span><span class="token number">20</span><span class="token punctuation">}</span><span class="token punctuation">]</span> from last<span class="token operator">-</span>known cluster state<span class="token punctuation">;</span> node term <span class="token number">0</span><span class="token punctuation">,</span> last<span class="token operator">-</span>accepted version <span class="token number">0</span> in term <span class="token number">0</span>
</code></pre>
<p><strong><code>解决办法：</code></strong></p>
<p>从提示信息上看，是网络问题，检查各个节点的 <code>network.publish_host</code> 配置地址是否通</p>
</li>
</ul>
<h4 id="三、IK-分词器安装"><a href="#三、IK-分词器安装" class="headerlink" title="三、IK 分词器安装"></a><code>三、IK 分词器安装</code></h4><ul>
<li><h5 id="插件安装"><a href="#插件安装" class="headerlink" title="插件安装"></a><code>插件安装</code></h5></li>
</ul>
<p>ik 分词器插件属于中文分词器插件，可以识别一段话中的词，并且可以指定分词策略甚至是自定义分词(例如，通过配置可以实现：八戒取经路就是牛作为一个词来识别,关于自定义分词规则，也是通过配置文件来实现，具体如何实现，自行查阅资料)</p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 ik<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># su - es</span>
<span class="token punctuation">[</span>es@centos7 ~<span class="token punctuation">]</span>$ <span class="token function">cd</span> /usr/local/elasticsearch/elasticsearch-7.8.0/plugins/
<span class="token punctuation">[</span>es@centos7 plugins<span class="token punctuation">]</span>$ <span class="token function">mkdir</span> ik -pv
<span class="token punctuation">[</span>es@centos7 plugins<span class="token punctuation">]</span>$ <span class="token function">cd</span> ik
<span class="token punctuation">[</span>es@centos7 ik<span class="token punctuation">]</span>$ <span class="token function">wget</span> https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.8.0/elasticsearch-analysis-ik-7.8.0.zip <span class="token comment" spellcheck="true">##下载版本要对应</span>
<span class="token punctuation">[</span>es@centos7 ik<span class="token punctuation">]</span>$ unzip elasticsearch-analysis-ik-7.8.0.zip <span class="token comment" spellcheck="true">## 解压</span>
</code></pre>
<ul>
<li><h5 id="验证"><a href="#验证" class="headerlink" title="验证"></a><code>验证</code></h5></li>
</ul>
<p>所有节点执行上面的插件安装，注意权限，然后启动所有节点，验证分词器是否生效：</p>
<ol>
<li><p><strong>没有指定分词器时的效果，会将搜索的汉字作为一个词</strong></p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 ik<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># curl -X GET -H "Content-Type: application/json"  "http://localhost:9200/_analyze?pretty=true" -d'{"text":"中华五千年华夏"}';</span>
<span class="token punctuation">{</span>
  <span class="token string">"tokens"</span> <span class="token keyword">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"中"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 0,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 1,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"&lt;IDEOGRAPHIC>"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 0
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"华"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 1,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 2,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"&lt;IDEOGRAPHIC>"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 1
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"五"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 2,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 3,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"&lt;IDEOGRAPHIC>"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 2
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"千"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 3,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 4,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"&lt;IDEOGRAPHIC>"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 3
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"年"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 4,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 5,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"&lt;IDEOGRAPHIC>"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 4
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"华"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 5,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 6,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"&lt;IDEOGRAPHIC>"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 5
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"夏"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 6,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 7,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"&lt;IDEOGRAPHIC>"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 6
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><strong>ik_max_word 和 ik_smart 分词策略</strong></p>
<ul>
<li><p><strong>ik_max_word</strong>: 将文本按最细粒度的组合来拆分，比如会将“中华五千年华夏”拆分为“五千年、五千、五千年华、华夏、千年华夏”，总之是可能的组合；</p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 ik<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># curl -X GET -H "Content-Type: application/json"  "http://localhost:9200/_analyze?pretty=true" -d'{"text":"中华五千年华夏","analyzer":"ik_smart"}';</span>
<span class="token punctuation">{</span>
  <span class="token string">"tokens"</span> <span class="token keyword">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"中华"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 0,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 2,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"CN_WORD"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 0
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"五千年"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 2,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 5,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"TYPE_CQUAN"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 1
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"华夏"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 5,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 7,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"CN_WORD"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 2
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
<li><p><strong>ik_smart</strong>: 最粗粒度的拆分，比如会将“五千年华夏”拆分为“五千年、华夏”</p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 ik<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># curl -X GET -H "Content-Type: application/json"  "http://localhost:9200/_analyze?pretty=true" -d'{"text":"中华五千年华夏","analyzer":"ik_max_word"}';</span>
<span class="token punctuation">{</span>
  <span class="token string">"tokens"</span> <span class="token keyword">:</span> <span class="token punctuation">[</span>
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"中华"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 0,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 2,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"CN_WORD"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 0
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"五千"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 2,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 4,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"TYPE_CNUM"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 1
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"千年"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 3,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 5,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"CN_WORD"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 2
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"年华"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 4,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 6,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"CN_WORD"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 3
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"年"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 4,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 5,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"COUNT"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 4
    <span class="token punctuation">}</span>,
    <span class="token punctuation">{</span>
      <span class="token string">"token"</span> <span class="token keyword">:</span> <span class="token string">"华夏"</span>,
      <span class="token string">"start_offset"</span> <span class="token keyword">:</span> 5,
      <span class="token string">"end_offset"</span> <span class="token keyword">:</span> 7,
      <span class="token string">"type"</span> <span class="token keyword">:</span> <span class="token string">"CN_WORD"</span>,
      <span class="token string">"position"</span> <span class="token keyword">:</span> 5
    <span class="token punctuation">}</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span>
</code></pre>
</li>
</ul>
</li>
</ol>
<h4 id="四、head-插件安装"><a href="#四、head-插件安装" class="headerlink" title="四、head 插件安装"></a><code>四、head 插件安装</code></h4><p><code>head</code> 插件就相当于 <code>ES</code> 的客户端工具，通过它，可以管理、操作 <code>ES</code> 中的数据。</p>
<ul>
<li><p>安装 <code>node</code> 环境</p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># wget https://npm.taobao.org/mirrors/node/v14.16.0/node-v14.16.0-linux-x64.tar.xz ## 下载 nodejs</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># yum -y install xz ##下载下来的jar包是xz格式的，一般的linux可能不识别，还需要安装xz.</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># xz -d node-v14.16.0-linux-x64.tar.xz ## 会在当前目录下生成一个 tar.gz 的包</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># mkdir /usr/local/node-v14 -pv</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># tar -xvf node-v14.16.0-linux-x64.tar.gz  -C /usr/local/node-v14/</span>
<span class="token comment" spellcheck="true">## 配置环境变量</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># vim /etc/profile.d/nodejs.sh</span>
<span class="token comment" spellcheck="true">## 添加如下内容</span>
<span class="token function">export</span> NODE_HOME<span class="token operator">=</span>/usr/local/node-v14/node-v14.16.0-linux-x64
<span class="token function">export</span> PATH<span class="token operator">=</span><span class="token variable">$PATH</span><span class="token keyword">:</span><span class="token variable">$NODE_HOME</span>/bin
<span class="token comment" spellcheck="true">## 重读环境变量</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true">#source /etc/profile</span>
<span class="token comment" spellcheck="true">##测试 node 是否生效</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># node -v</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># npm -v</span>
<span class="token comment" spellcheck="true">##安装cnpm</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># npm install -g cnpm --registry=https://registry.npm.taobao.org</span>
<span class="token comment" spellcheck="true">## 安装 grunt 工具，用于打包、压缩、测试、执行等工作</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># cnpm install -g grunt-cli</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># grunt -version ## 查看是否安装成功</span>
</code></pre>
</li>
<li><p>安装 <code>head</code> </p>
<pre class=" language-bash"><code class="language-bash">访问地址https://codechina.csdn.net/mirrors/mobz/elasticsearch-head?utm_source<span class="token operator">=</span>csdn_github_accelerator，下载
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># wget https://codechina.csdn.net/mirrors/mobz/elasticsearch-head/-/archive/master/elasticsearch-head-master.zip</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># mkdir /usr/local/elasticsearch-head</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># tar -xvf elasticsearch-head-master.zip -C /usr/local/elasticsearch-head</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># cd /usr/local/elasticsearch-head/elasticsearch-head-master</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># cnpm install ## 安装</span>
</code></pre>
</li>
<li><p>运行 <code>head</code> </p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># grunt server ## 启动</span>
 或者在head的主目录中运行npm run start也是可以运行head的
 在浏览器上输入：http://192.168.56.143:9100/ 即可访问
</code></pre>
</li>
</ul>
<h4 id="五、Kibana-安装"><a href="#五、Kibana-安装" class="headerlink" title="五、Kibana 安装"></a><code>五、Kibana 安装</code></h4><p><code>Kibana</code> 是 <code>ELK</code> 中的 <code>K</code> , 它是 <code>ES</code> 的客户端，通过该工具可以很方便基于 <code>Rest API</code> 操作 <code>ES</code> 实例，接下来简单介绍安装过程。</p>
<pre class=" language-bash"><code class="language-bash"><span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># wget https://artifacts.elastic.co/downloads/kibana/kibana-7.8.0-linux-x86_64.tar.gz ## 下载安装包，注意安装包要和 ES 保持一致</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># mkdir /usr/local/kibana</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># tar -zxvf kibana-7.8.0-linux-x86_64.tar.gz -C /usr/local/kibana</span>
<span class="token punctuation">[</span>root@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true">#  su - es</span>
<span class="token punctuation">[</span>es@centos7 ~<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># cd /usr/local/</span>
<span class="token punctuation">[</span>es@centos7 local<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># chown -R es:es ./kibana ## 修改权限</span>
<span class="token punctuation">[</span>es@centos7 local<span class="token punctuation">]</span><span class="token comment" spellcheck="true"># vim ./kibana/kibana-7.8.0-linux-x86_64/config/kibana.yml ## 修改配置</span>
<span class="token comment" spellcheck="true"># 放开注释,将默认配置改成如下：</span>
server.port: 5601
server.host: <span class="token string">"0.0.0.0"</span>
<span class="token comment" spellcheck="true">#elasticsearch.url: "http://你的服务器外网ip（your domain）:9200"</span>
elasticsearch.hosts: <span class="token punctuation">[</span><span class="token string">"http://192.168.56.143:9200"</span><span class="token punctuation">]</span>  <span class="token comment" spellcheck="true">## 连接的节点</span>
kibana.index: <span class="token string">".kibana"</span>
i18n.locale: <span class="token string">"zh-CN"</span>  <span class="token comment" spellcheck="true">## 修改为中文</span>
</code></pre>
<p>打开浏览器，访问 <a target="_blank" rel="noopener" href="http://192.168.56.143:9200/">http://192.168.56.143:9200</a> ：</p>
<img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/image-20210412211527798.png" alt="image-20210412211527798" style="zoom:80%;">

<p><code>具体的 ES 的 CRUD API 咋使用，后面我再计划出一篇文章介绍。</code></p>
<h4 id="六、安装-cerebro-集群管理工具"><a href="#六、安装-cerebro-集群管理工具" class="headerlink" title="六、安装 cerebro 集群管理工具"></a><code>六、安装 cerebro 集群管理工具</code></h4><p><code>cerebro</code> 和 <code>head</code> 、<code>Kibana</code> 客户端类似，它能更直观的验证和管理集群，cerebro 界面我觉得比较炫酷些。</p>
<p><a target="_blank" rel="noopener" href="https://github.com/lmenezes/cerebro">下载 cerebro</a> </p>
<img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/image-20210412215347355.png" alt="image-20210412215347355" style="zoom:80%;">

<img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/image-20210412215316444.png" alt="image-20210412215316444" style="zoom:70%;">

<p>安装过程直接 <code>unzip</code> 解压，然后进入 <code>cerebro/bin</code> 运行 <code>./cerbro</code> 启动，在浏览器中访问 <a target="_blank" rel="noopener" href="http://192.168.56.143:9000/">http://192.168.56.143:9000</a> 最终显示的结果如下：</p>
<img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/image-20210412220123982.png" alt="image-20210412220123982" style="zoom:80%;">

<img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/image-20210412220302829.png" alt="image-20210412220302829" style="zoom:80%;">

<h4 id="七、验证-ES-集群故障转移"><a href="#七、验证-ES-集群故障转移" class="headerlink" title="七、验证 ES 集群故障转移"></a><code>七、验证 ES 集群故障转移</code></h4><p>注意实心星号的是主节点，我们尝试将 <code>192.168.56.145</code> 节点服务关闭，验证，主节点是否进行重新选举，并再次启动 <code>192.168.56.145</code>，看看是否变成候选节点：</p>
<img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/image-20210412220605588.png" alt="image-20210412220605588" style="zoom:80%;">

<p>发现 <code>192.168.56.143</code> 变成了主节点，然后启动 <code>192.168.56.145</code>，验证其是否变成了候选节点</p>
<p>​    <img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/image-20210412220937330.png" alt="image-20210412220937330" style="zoom:80%;"></p>
<p>验证结果，和自己理解的一致。</p>
<p>默认创建索引时，如果不指定分片数量，和分片副本数量，默认只会创建一个分片，没有副本，所以为了保证高可用，在创建索引时候需要指定分片数和副本数：</p>
<pre class=" language-yaml"><code class="language-yaml"><span class="token comment" spellcheck="true">## 定义创建索引的模板，凡是以 user 名称开头的索引都会根据这个模板规则去创建索引</span>
<span class="token comment" spellcheck="true">## 在 Kibana 上执行</span>
POST _template/template_1
<span class="token punctuation">{</span>
  <span class="token key atrule">"index_patterns"</span><span class="token punctuation">:</span> <span class="token punctuation">[</span>
    <span class="token string">"user*"</span>
  <span class="token punctuation">]</span><span class="token punctuation">,</span>
  <span class="token key atrule">"settings"</span><span class="token punctuation">:</span> <span class="token punctuation">{</span>
    <span class="token key atrule">"number_of_shards"</span><span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span>  <span class="token comment" spellcheck="true">## 三个主分片</span>
    <span class="token key atrule">"number_of_replicas"</span><span class="token punctuation">:</span> <span class="token number">1 </span><span class="token comment" spellcheck="true">## 每一个主分片一个副本</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
<span class="token comment" spellcheck="true">## 在 Kibana 上执行创建索引,创建后的索引包含 3 个主分片，每一个主分片有一个副本分片</span>
PUT /user
</code></pre>
<p>然后关闭主节点，发现另外两个节点还有完整的3个分片可以用，关闭从节点，发现也一样（注意在做验证时，需要多刷新几次，默认30秒分片才会切换完成，虚线的表示副本分片，实线的表示主分片）</p>
<p><img src="https://gitee.com/CodeJourney/source_file/raw/master/blog_img/image-20210412231449712.png" alt="image-20210412231449712"></p>
<h4 id="八、开机启动脚本及配置"><a href="#八、开机启动脚本及配置" class="headerlink" title="八、开机启动脚本及配置"></a><code>八、开机启动脚本及配置</code></h4><p><code>ES</code> 开机启动配置</p>
<p>在**<code>/etc/init.d</code><strong>目录下新建文件</strong><code>elasticsearch</code>**，添加如下内容：</p>
<pre class=" language-bash"><code class="language-bash"><span class="token shebang important">#!/bin/sh</span>
<span class="token comment" spellcheck="true">#chkconfig:</span>
<span class="token comment" spellcheck="true">#description: elasticsearch</span>
 
<span class="token function">export</span> JAVA_HOME<span class="token operator">=</span>/usr/local/java/jdk1.8.0_112
<span class="token function">export</span> JAVA_BIN<span class="token operator">=</span>/usr/local/java/jdk1.8.0_112/bin
<span class="token function">export</span> PATH<span class="token operator">=</span><span class="token variable">$PATH</span><span class="token keyword">:</span><span class="token variable">$JAVA_HOME</span>/bin
<span class="token function">export</span> CLASSPATH<span class="token operator">=</span>.:<span class="token variable">$JAVA_HOME</span>/lib/dt.jar:<span class="token variable">$JAVA_HOME</span>/lib/tools.jar
<span class="token function">export</span> JAVA_HOME JAVA_BIN PATH CLASSPATH
 
<span class="token keyword">case</span> <span class="token string">"<span class="token variable">$1</span>"</span> <span class="token keyword">in</span>
start<span class="token punctuation">)</span>
<span class="token comment" spellcheck="true">#下面的“&lt;&lt;!”是切换用户后，待执行的命令，执行完后使用“!”来进行结束</span>
    <span class="token function">su</span> es<span class="token operator">&lt;&lt;</span><span class="token operator">!</span>
    <span class="token function">cd</span> 你的elasticsearch主目录
    ./bin/elasticsearch -d
<span class="token operator">!</span>
<span class="token comment" spellcheck="true">#上面的“!”是以上面的对应起来，并且顶格放置，这是语法</span>
    <span class="token keyword">echo</span> <span class="token string">"elasticsearch startup"</span> <span class="token comment" spellcheck="true">#将该行替换成你自己的服务启动命令</span>
    <span class="token punctuation">;</span><span class="token punctuation">;</span>  
stop<span class="token punctuation">)</span>
    es_pid<span class="token operator">=</span>`ps aux<span class="token operator">|</span><span class="token function">grep</span> elasticsearch <span class="token operator">|</span> <span class="token function">grep</span> -v <span class="token string">'grep elasticsearch'</span> <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{print <span class="token variable">$2</span>}'</span>`
    <span class="token function">kill</span> -9 <span class="token variable">$es_pid</span>
    <span class="token keyword">echo</span> <span class="token string">"elasticsearch stopped"</span>
    <span class="token punctuation">;</span><span class="token punctuation">;</span>  
restart<span class="token punctuation">)</span>
    es_pid<span class="token operator">=</span>`ps aux<span class="token operator">|</span><span class="token function">grep</span> elasticsearch <span class="token operator">|</span> <span class="token function">grep</span> -v <span class="token string">'grep elasticsearch'</span> <span class="token operator">|</span> <span class="token function">awk</span> <span class="token string">'{print <span class="token variable">$2</span>}'</span>`
    <span class="token function">kill</span> -9 <span class="token variable">$es_pid</span>
    <span class="token keyword">echo</span> <span class="token string">"elasticsearch stopped"</span>
    <span class="token function">su</span> es<span class="token operator">&lt;&lt;</span><span class="token operator">!</span>
    <span class="token function">cd</span> 你的elasticsearch主目录
    ./bin/elasticsearch -d
<span class="token operator">!</span>
    <span class="token keyword">echo</span> <span class="token string">"es startup"</span>
    <span class="token punctuation">;</span><span class="token punctuation">;</span>  
*<span class="token punctuation">)</span>
    <span class="token keyword">echo</span> <span class="token string">"start|stop|restart"</span>
    <span class="token punctuation">;</span><span class="token punctuation">;</span>  
esac
 
<span class="token keyword">exit</span> <span class="token variable">$?</span>
</code></pre>
<pre class=" language-bash"><code class="language-bash"><span class="token function">chmod</span> +x elasticsearch 添加执行权限记得是给 es
<span class="token function">sudo</span> <span class="token function">chkconfig</span> --add /etc/init.d/elasticsearch <span class="token comment" spellcheck="true">## 加入开启启动项</span>
以后使用service elasticsearch start/stop/restart来管理服务
</code></pre>
<p><code>elasticsearch-head</code> 开机启动配置</p>
<p>在**<code>/etc/init.d</code><strong>目录下新建文件</strong><code>elasticsearch_head</code>**，添加如下内容：</p>
<pre class=" language-bash"><code class="language-bash"><span class="token shebang important">#!/bin/sh</span>
<span class="token comment" spellcheck="true">#chkconfig: 2345 80 05</span>
<span class="token comment" spellcheck="true">#description: es_head_run</span>
 
<span class="token function">export</span> NODE_PATH<span class="token operator">=</span>/home/soft/node-v8.11.1-linux-x64
<span class="token function">export</span> PATH<span class="token operator">=</span><span class="token variable">$PATH</span><span class="token keyword">:</span><span class="token variable">$NODE_PATH</span>/bin
<span class="token comment" spellcheck="true">#如果centOs使用yum命令安装了nodejs就不用输入上面两行export语句了，因为yum安装自动配置好了</span>
 
<span class="token function">cd</span> /home/soft/elasticsearch-head-master
<span class="token function">nohup</span> <span class="token function">npm</span> run start <span class="token operator">></span>/home/soft/elasticsearch-head-master/nohup.out 2<span class="token operator">></span><span class="token operator">&amp;</span>1 <span class="token operator">&amp;</span>
</code></pre>
<pre class=" language-bash"><code class="language-bash"><span class="token function">chmod</span> +x elasticsearch_head 添加执行权限记得是给 es
<span class="token function">sudo</span> <span class="token function">chkconfig</span> --add /etc/init.d/elasticsearch_head <span class="token comment" spellcheck="true">## 加入开启启动项</span>
以后使用service elasticsearch_head start/stop/restart来管理服务
</code></pre>
<h4 id="九、参考文献"><a href="#九、参考文献" class="headerlink" title="九、参考文献"></a><code>九、参考文献</code></h4><p><a target="_blank" rel="noopener" href="https://blog.csdn.net/qq_38680405/article/details/107225724">参考文献1</a></p>
<h4 id="十、下篇预告"><a href="#十、下篇预告" class="headerlink" title="十、下篇预告"></a><code>十、下篇预告</code></h4><p>《基于 Kibana 客户端操作 ES -增删改查API篇》</p>

                
            </div>
            <hr/>

            

    <div class="reprint" id="reprint-statement">
        
            <div class="reprint__author">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-user">
                        文章作者:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="/about" rel="external nofollow noreferrer">八戒取经路</a>
                </span>
            </div>
            <div class="reprint__type">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-link">
                        文章链接:
                    </i>
                </span>
                <span class="reprint-info">
                    <a href="https://codejourney.gitee.io/2021/04/11/ES%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA%E4%B8%8EKibana-head-IK%E9%85%8D%E7%BD%AE/">https://codejourney.gitee.io/2021/04/11/ES%E9%9B%86%E7%BE%A4%E6%90%AD%E5%BB%BA%E4%B8%8EKibana-head-IK%E9%85%8D%E7%BD%AE/</a>
                </span>
            </div>
            <div class="reprint__notice">
                <span class="reprint-meta" style="font-weight: bold;">
                    <i class="fas fa-copyright">
                        版权声明:
                    </i>
                </span>
                <span class="reprint-info">
                    本博客所有文章除特別声明外，均采用
                    <a href="https://creativecommons.org/licenses/by/4.0/deed.zh" rel="external nofollow noreferrer" target="_blank">CC BY 4.0</a>
                    许可协议。转载请注明来源
                    <a href="/about" target="_blank">八戒取经路</a>
                    !
                </span>
            </div>
        
    </div>

    <script async defer>
      document.addEventListener("copy", function (e) {
        let toastHTML = '<span>复制成功，请遵循本文的转载规则</span><button class="btn-flat toast-action" onclick="navToReprintStatement()" style="font-size: smaller">查看</a>';
        M.toast({html: toastHTML})
      });

      function navToReprintStatement() {
        $("html, body").animate({scrollTop: $("#reprint-statement").offset().top - 80}, 800);
      }
    </script>



            <div class="tag_share" style="display: block;">
                <div class="post-meta__tag-list" style="display: inline-block;">
                    
                        <div class="article-tag">
                            
                                <a href="/tags/Elasticsearch%E9%9B%86%E7%BE%A4/">
                                    <span class="chip bg-color">Elasticsearch集群</span>
                                </a>
                            
                                <a href="/tags/IK/">
                                    <span class="chip bg-color">IK</span>
                                </a>
                            
                                <a href="/tags/Kibana/">
                                    <span class="chip bg-color">Kibana</span>
                                </a>
                            
                                <a href="/tags/head%E6%8F%92%E4%BB%B6/">
                                    <span class="chip bg-color">head插件</span>
                                </a>
                            
                        </div>
                    
                </div>
                <div class="post_share" style="zoom: 80%; width: fit-content; display: inline-block; float: right; margin: -0.15rem 0;">
                    <link rel="stylesheet" type="text/css" href="/libs/share/css/share.min.css">
<div id="article-share">

    
    <div class="social-share" data-sites="twitter,facebook,google,qq,qzone,wechat,weibo,douban,linkedin" data-wechat-qrcode-helper="<p>微信扫一扫即可分享！</p>"></div>
    <script src="/libs/share/js/social-share.min.js"></script>
    

    

</div>

                </div>
            </div>
            
                <style>
    #reward {
        margin: 40px 0;
        text-align: center;
    }

    #reward .reward-link {
        font-size: 1.4rem;
        line-height: 38px;
    }

    #reward .btn-floating:hover {
        box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2), 0 5px 15px rgba(0, 0, 0, 0.2);
    }

    #rewardModal {
        width: 320px;
        height: 350px;
    }

    #rewardModal .reward-title {
        margin: 15px auto;
        padding-bottom: 5px;
    }

    #rewardModal .modal-content {
        padding: 10px;
    }

    #rewardModal .close {
        position: absolute;
        right: 15px;
        top: 15px;
        color: rgba(0, 0, 0, 0.5);
        font-size: 1.3rem;
        line-height: 20px;
        cursor: pointer;
    }

    #rewardModal .close:hover {
        color: #ef5350;
        transform: scale(1.3);
        -moz-transform:scale(1.3);
        -webkit-transform:scale(1.3);
        -o-transform:scale(1.3);
    }

    #rewardModal .reward-tabs {
        margin: 0 auto;
        width: 210px;
    }

    .reward-tabs .tabs {
        height: 38px;
        margin: 10px auto;
        padding-left: 0;
    }

    .reward-content ul {
        padding-left: 0 !important;
    }

    .reward-tabs .tabs .tab {
        height: 38px;
        line-height: 38px;
    }

    .reward-tabs .tab a {
        color: #fff;
        background-color: #ccc;
    }

    .reward-tabs .tab a:hover {
        background-color: #ccc;
        color: #fff;
    }

    .reward-tabs .wechat-tab .active {
        color: #fff !important;
        background-color: #22AB38 !important;
    }

    .reward-tabs .alipay-tab .active {
        color: #fff !important;
        background-color: #019FE8 !important;
    }

    .reward-tabs .reward-img {
        width: 210px;
        height: 210px;
    }
</style>

<div id="reward">
    <a href="#rewardModal" class="reward-link modal-trigger btn-floating btn-medium waves-effect waves-light red">赏</a>

    <!-- Modal Structure -->
    <div id="rewardModal" class="modal">
        <div class="modal-content">
            <a class="close modal-close"><i class="fas fa-times"></i></a>
            <h4 class="reward-title">你的赏识是我前进的动力</h4>
            <div class="reward-content">
                <div class="reward-tabs">
                    <ul class="tabs row">
                        <li class="tab col s6 alipay-tab waves-effect waves-light"><a href="#alipay">支付宝</a></li>
                        <li class="tab col s6 wechat-tab waves-effect waves-light"><a href="#wechat">微 信</a></li>
                    </ul>
                    <div id="alipay">
                        <img src="/medias/reward/alipay.jpg" class="reward-img" alt="支付宝打赏二维码">
                    </div>
                    <div id="wechat">
                        <img src="/medias/reward/wechat.png" class="reward-img" alt="微信打赏二维码">
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script>
    $(function () {
        $('.tabs').tabs();
    });
</script>

            
        </div>
    </div>

    

    

    

    

    

    

    

    

    

<article id="prenext-posts" class="prev-next articles">
    <div class="row article-row">
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge left-badge text-color">
                <i class="fas fa-chevron-left"></i>&nbsp;上一篇</div>
            <div class="card">
                <a href="/2021/04/13/%E5%9F%BA%E4%BA%8E-Kibana-%E5%AE%A2%E6%88%B7%E7%AB%AF%E6%93%8D%E4%BD%9C-ES-%E5%A2%9E%E5%88%A0%E6%94%B9%E6%9F%A5API%E7%AF%87/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/9.jpg" class="responsive-img" alt="基于 Kibana 客户端操作 ES -增删改查API篇">
                        
                        <span class="card-title">基于 Kibana 客户端操作 ES -增删改查API篇</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                        <span class="publish-date">
                            <i class="far fa-clock fa-fw icon-date"></i>2021-04-13
                        </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            八戒取经路
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/ES/">
                        <span class="chip bg-color">ES</span>
                    </a>
                    
                    <a href="/tags/API/">
                        <span class="chip bg-color">API</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
        
        <div class="article col s12 m6" data-aos="fade-up">
            <div class="article-badge right-badge text-color">
                下一篇&nbsp;<i class="fas fa-chevron-right"></i>
            </div>
            <div class="card">
                <a href="/2021/04/07/ElasticSearch%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86%E8%A7%A3%E8%AF%BB/">
                    <div class="card-image">
                        
                        
                        <img src="/medias/featureimages/19.jpg" class="responsive-img" alt="ElasticSearch工作原理解读">
                        
                        <span class="card-title">ElasticSearch工作原理解读</span>
                    </div>
                </a>
                <div class="card-content article-content">
                    <div class="summary block-with-text">
                        
                            
                        
                    </div>
                    <div class="publish-info">
                            <span class="publish-date">
                                <i class="far fa-clock fa-fw icon-date"></i>2021-04-07
                            </span>
                        <span class="publish-author">
                            
                            <i class="fas fa-user fa-fw"></i>
                            八戒取经路
                            
                        </span>
                    </div>
                </div>
                
                <div class="card-action article-tags">
                    
                    <a href="/tags/ElasticSearch/">
                        <span class="chip bg-color">ElasticSearch</span>
                    </a>
                    
                </div>
                
            </div>
        </div>
        
    </div>
</article>

</div>



<!-- 代码块功能依赖 -->
<script type="text/javascript" src="/libs/codeBlock/codeBlockFuction.js"></script>

<!-- 代码语言 -->

<script type="text/javascript" src="/libs/codeBlock/codeLang.js"></script>


<!-- 代码块复制 -->

<script type="text/javascript" src="/libs/codeBlock/codeCopy.js"></script>


<!-- 代码块收缩 -->

<script type="text/javascript" src="/libs/codeBlock/codeShrink.js"></script>


    </div>
    <div id="toc-aside" class="expanded col l3 hide-on-med-and-down">
        <div class="toc-widget card" style="background-color: white;">
            <div class="toc-title"><i class="far fa-list-alt"></i>&nbsp;&nbsp;目录</div>
            <div id="toc-content"></div>
        </div>
    </div>
</div>

<!-- TOC 悬浮按钮. -->

<div id="floating-toc-btn" class="hide-on-med-and-down">
    <a class="btn-floating btn-large bg-color">
        <i class="fas fa-list-ul"></i>
    </a>
</div>


<script src="/libs/tocbot/tocbot.min.js"></script>
<script>
    $(function () {
        tocbot.init({
            tocSelector: '#toc-content',
            contentSelector: '#articleContent',
            headingsOffset: -($(window).height() * 0.4 - 45),
            collapseDepth: Number('0'),
            headingSelector: 'h2, h3, h4'
        });

        // modify the toc link href to support Chinese.
        let i = 0;
        let tocHeading = 'toc-heading-';
        $('#toc-content a').each(function () {
            $(this).attr('href', '#' + tocHeading + (++i));
        });

        // modify the heading title id to support Chinese.
        i = 0;
        $('#articleContent').children('h2, h3, h4').each(function () {
            $(this).attr('id', tocHeading + (++i));
        });

        // Set scroll toc fixed.
        let tocHeight = parseInt($(window).height() * 0.4 - 64);
        let $tocWidget = $('.toc-widget');
        $(window).scroll(function () {
            let scroll = $(window).scrollTop();
            /* add post toc fixed. */
            if (scroll > tocHeight) {
                $tocWidget.addClass('toc-fixed');
            } else {
                $tocWidget.removeClass('toc-fixed');
            }
        });

        
        /* 修复文章卡片 div 的宽度. */
        let fixPostCardWidth = function (srcId, targetId) {
            let srcDiv = $('#' + srcId);
            if (srcDiv.length === 0) {
                return;
            }

            let w = srcDiv.width();
            if (w >= 450) {
                w = w + 21;
            } else if (w >= 350 && w < 450) {
                w = w + 18;
            } else if (w >= 300 && w < 350) {
                w = w + 16;
            } else {
                w = w + 14;
            }
            $('#' + targetId).width(w);
        };

        // 切换TOC目录展开收缩的相关操作.
        const expandedClass = 'expanded';
        let $tocAside = $('#toc-aside');
        let $mainContent = $('#main-content');
        $('#floating-toc-btn .btn-floating').click(function () {
            if ($tocAside.hasClass(expandedClass)) {
                $tocAside.removeClass(expandedClass).hide();
                $mainContent.removeClass('l9');
            } else {
                $tocAside.addClass(expandedClass).show();
                $mainContent.addClass('l9');
            }
            fixPostCardWidth('artDetail', 'prenext-posts');
        });
        
    });
</script>

    

</main>




    <footer class="page-footer bg-color">
    
        <link rel="stylesheet" href="/libs/aplayer/APlayer.min.css">
<style>
    .aplayer .aplayer-lrc p {
        
        display: none;
        
        font-size: 12px;
        font-weight: 700;
        line-height: 16px !important;
    }

    .aplayer .aplayer-lrc p.aplayer-lrc-current {
        
        display: none;
        
        font-size: 15px;
        color: #42b983;
    }

    
    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body {
        left: -66px !important;
    }

    .aplayer.aplayer-fixed.aplayer-narrow .aplayer-body:hover {
        left: 0px !important;
    }

    
</style>
<div class="">
    
    <div class="row">
        <meting-js class="col l8 offset-l2 m10 offset-m1 s12"
                   server="netease"
                   type="playlist"
                   id="503838841"
                   fixed='true'
                   autoplay='false'
                   theme='#42b983'
                   loop='all'
                   order='random'
                   preload='auto'
                   volume='0.7'
                   list-folded='true'
        >
        </meting-js>
    </div>
</div>

<script src="/libs/aplayer/APlayer.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/meting@2/dist/Meting.min.js"></script>

    
    <div class="container row center-align" style="margin-bottom: 0px !important;">
        <div class="col s12 m8 l8 copy-right">
            Copyright&nbsp;&copy;
            
                <span id="year">2019-2021</span>
            
            <span id="year">2019</span>
            <a href="/about" target="_blank">八戒取经路</a>
            |&nbsp;Powered by&nbsp;<a href="https://hexo.io/" target="_blank">Hexo</a>
            |&nbsp;Theme&nbsp;<a href="https://github.com/" target="_blank">Matery</a>
            <br>
            
            
            
            
            
            
            <span id="busuanzi_container_site_pv">
                |&nbsp;<i class="far fa-eye"></i>&nbsp;总访问量:&nbsp;<span id="busuanzi_value_site_pv"
                    class="white-color"></span>&nbsp;次
            </span>
            
            
            <span id="busuanzi_container_site_uv">
                |&nbsp;<i class="fas fa-users"></i>&nbsp;总访问人数:&nbsp;<span id="busuanzi_value_site_uv"
                    class="white-color"></span>&nbsp;人
            </span>
            
            <br>
            
            <br>
            
        </div>
        <div class="col s12 m4 l4 social-link social-statis">
    <a href="https://github.com/blinkfox" class="tooltipped" target="_blank" data-tooltip="访问我的GitHub" data-position="top" data-delay="50">
        <i class="fab fa-github"></i>
    </a>



    <a href="mailto:843355928@qq.com" class="tooltipped" target="_blank" data-tooltip="邮件联系我" data-position="top" data-delay="50">
        <i class="fas fa-envelope-open"></i>
    </a>







    <a href="tencent://AddContact/?fromId=50&fromSubId=1&subcmd=all&uin=843355928" class="tooltipped" target="_blank" data-tooltip="QQ联系我: 843355928" data-position="top" data-delay="50">
        <i class="fab fa-qq"></i>
    </a>







    <a href="/atom.xml" class="tooltipped" target="_blank" data-tooltip="RSS 订阅" data-position="top" data-delay="50">
        <i class="fas fa-rss"></i>
    </a>

</div>
    </div>
</footer>

<div class="progress-bar"></div>


    <!-- 搜索遮罩框 -->
<div id="searchModal" class="modal">
    <div class="modal-content">
        <div class="search-header">
            <span class="title"><i class="fas fa-search"></i>&nbsp;&nbsp;搜索</span>
            <input type="search" id="searchInput" name="s" placeholder="请输入搜索的关键字"
                   class="search-input">
        </div>
        <div id="searchResult"></div>
    </div>
</div>

<script type="text/javascript">
$(function () {
    var searchFunc = function (path, search_id, content_id) {
        'use strict';
        $.ajax({
            url: path,
            dataType: "xml",
            success: function (xmlResponse) {
                // get the contents from search data
                var datas = $("entry", xmlResponse).map(function () {
                    return {
                        title: $("title", this).text(),
                        content: $("content", this).text(),
                        url: $("url", this).text()
                    };
                }).get();
                var $input = document.getElementById(search_id);
                var $resultContent = document.getElementById(content_id);
                $input.addEventListener('input', function () {
                    var str = '<ul class=\"search-result-list\">';
                    var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                    $resultContent.innerHTML = "";
                    if (this.value.trim().length <= 0) {
                        return;
                    }
                    // perform local searching
                    datas.forEach(function (data) {
                        var isMatch = true;
                        var data_title = data.title.trim().toLowerCase();
                        var data_content = data.content.trim().replace(/<[^>]+>/g, "").toLowerCase();
                        var data_url = data.url;
                        data_url = data_url.indexOf('/') === 0 ? data.url : '/' + data_url;
                        var index_title = -1;
                        var index_content = -1;
                        var first_occur = -1;
                        // only match artiles with not empty titles and contents
                        if (data_title !== '' && data_content !== '') {
                            keywords.forEach(function (keyword, i) {
                                index_title = data_title.indexOf(keyword);
                                index_content = data_content.indexOf(keyword);
                                if (index_title < 0 && index_content < 0) {
                                    isMatch = false;
                                } else {
                                    if (index_content < 0) {
                                        index_content = 0;
                                    }
                                    if (i === 0) {
                                        first_occur = index_content;
                                    }
                                }
                            });
                        }
                        // show search results
                        if (isMatch) {
                            str += "<li><a href='" + data_url + "' class='search-result-title'>" + data_title + "</a>";
                            var content = data.content.trim().replace(/<[^>]+>/g, "");
                            if (first_occur >= 0) {
                                // cut out 100 characters
                                var start = first_occur - 20;
                                var end = first_occur + 80;
                                if (start < 0) {
                                    start = 0;
                                }
                                if (start === 0) {
                                    end = 100;
                                }
                                if (end > content.length) {
                                    end = content.length;
                                }
                                var match_content = content.substr(start, end);
                                // highlight all keywords
                                keywords.forEach(function (keyword) {
                                    var regS = new RegExp(keyword, "gi");
                                    match_content = match_content.replace(regS, "<em class=\"search-keyword\">" + keyword + "</em>");
                                });

                                str += "<p class=\"search-result\">" + match_content + "...</p>"
                            }
                            str += "</li>";
                        }
                    });
                    str += "</ul>";
                    $resultContent.innerHTML = str;
                });
            }
        });
    };

    searchFunc('/search.xml', 'searchInput', 'searchResult');
});
</script>

    <!-- 回到顶部按钮 -->
<div id="backTop" class="top-scroll">
    <a class="btn-floating btn-large waves-effect waves-light" href="#!">
        <i class="fas fa-arrow-up"></i>
    </a>
</div>


    <script src="/libs/materialize/materialize.min.js"></script>
    <script src="/libs/masonry/masonry.pkgd.min.js"></script>
    <script src="/libs/aos/aos.js"></script>
    <script src="/libs/scrollprogress/scrollProgress.min.js"></script>
    <script src="/libs/lightGallery/js/lightgallery-all.min.js"></script>
    <script src="/js/matery.js"></script>

    <!-- Baidu Analytics -->

    <!-- Baidu Push -->

<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        } else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>

    
    <script src="/libs/others/clicklove.js" async="async"></script>
    
    
    <script async src="/libs/others/busuanzi.pure.mini.js"></script>
    

    

    

    <!--腾讯兔小巢-->
    
    

    

    

    
    <script src="/libs/instantpage/instantpage.js" type="module"></script>
    

</body>

</html>
